package com.time.company.db;

import android.app.Activity;

import com.time.company.app.MyApplication;
import com.time.company.db.dao.impl.DynamicsDao;
import com.time.company.db.dao.impl.UserDao;
import com.time.company.db.model.DynamicsModel;
import com.time.company.db.model.UserModel;
import com.time.company.servermodel.User;
import com.time.company.servermodel.dynamics.Dynamics;

/**
 * 处理Model
 * Created by Bing on 2016/8/24.
 * E-mail is tx16bing@163.com
 */
public class ModelCreator {

    private static ModelCreator modelCreator;
    private MyApplication application;

    private ModelCreator(MyApplication application) {
        this.application = application;
    }

    public static synchronized ModelCreator getInstance(MyApplication application) {

        if (modelCreator == null) {
            modelCreator = new ModelCreator(application);
        }
        return modelCreator;
    }

    public static synchronized ModelCreator getInstance(Activity activity) {

        if (modelCreator == null) {
            modelCreator = new ModelCreator((MyApplication) activity.getApplication());
        }
        return modelCreator;
    }

    // 保存用户资料
    public UserModel setUserModel(User user) {
        UserModel model = new UserModel(user);
        UserDao dao = new UserDao();
        dao.save(model);
        return model;
    }


    public DynamicsModel setDynamicsModel(Dynamics dynamics) {
        DynamicsModel dynamicsModel = new DynamicsModel(dynamics);
        new DynamicsDao().save(dynamicsModel);
        return dynamicsModel;
    }
}
